function addPrefix(str) {
    return '$' + str;
}
function len(str) {
    return str.length;
}
function sum(a, b) {
    return a + b
}

const compose = (...fns) => {
    return fns.reduce(function(a, b) {
        return function (...args) {
            return a(b(...args));
        }
    })
}

let final = compose(addPrefix, len, sum);
const r = final('a', 'b');
console.log(r); // $2
